package com.reremouse.util;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

public class SpringHelper {
    private static ApplicationContext ac = null;

    public static <T> T getSpringBean(String name) {
        synchronized (ApplicationContext.class) {
            if (ac == null) {
                ac = getSpringApplicationCtx();
            }
        }
        T bean = (T) ac.getBean(name);
        return bean;
    }

    public static ApplicationContext getSpringApplicationCtx() {
        ApplicationContext ctx = getSpringWebCtx();
        if (ctx == null) {
        }
        return ctx;
    }

    public static ApplicationContext getSpringWebCtx() {
        ServletContext sc = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        if (sc != null) {
            WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
            return wac;
        }
        return null;
    }

    public static void buildSpringWebCtx(ServletContext sc) {
        ac = WebApplicationContextUtils.getWebApplicationContext(sc);
    }

    public static void main(String[] args) {
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.util.SpringHelper

 * JD-Core Version:    0.7.0.1

 */